package za.co.telkom.popnumbers.web.email;

import javax.mail.MessagingException;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;
@Component
public class PopNumberEmail {

    private static final Logger logger = Logger.getLogger(PopNumberEmail.class);
    @Autowired
    private JavaMailSender mailSender;
    private String ccEmailAddress;

    public String getCcEmailAddress() {
		return ccEmailAddress;
	}

	public void setCcEmailAddress(String ccEmailAddress) {
		this.ccEmailAddress = ccEmailAddress;
	}

	public JavaMailSender getMailSender() {
    return mailSender;
    }

    public void setMailSender(JavaMailSender mailSender) {
    this.mailSender = mailSender;
    }

    public void sendEmail(String toAddress, String message) {
    javax.mail.internet.MimeMessage mailMessage = mailSender.createMimeMessage();
    MimeMessageHelper helper = new MimeMessageHelper(mailMessage);
    System.out.println("Mail addresses:"+toAddress);
    System.out.println("CCMail addresses 1:"+ccEmailAddress);
    String fromAddress=ccEmailAddress;
    try {
       helper.setText(message, true);
        helper.setTo(toAddress);
        helper.setCc(ccEmailAddress);
        helper.setSubject("Telkom SurfMore : Confirmation Required");
        helper.setFrom(fromAddress);
	    logger.debug("Sending Message..");
        mailSender.send(mailMessage);
        }
   catch (MessagingException e) {
        logger.error("Exception", e);
        }
    }

 


}
